

.PHONY: bootloader application tools image
# default action : build all
all: bootloader application image tools

PWD = $(shell pwd)
CVIMG = $(PWD)/tools/cvimg/cvimg
MGBIN = $(PWD)/tools/mgbin/mgbin

bootloader:
	@echo "Build lynxi mcu bootloader!!!!!!!!!!!!!!!!"
	make -f common.mk BUILD_TARGET=boot

application:
	@echo "Build lynxi mcu application!!!!!!!!!!!!!!!!"
	make -f common.mk BUILD_TARGET=application
tools:
	@echo "Build tools!!!!!!!!!!!!!!!!!!!!!!!"
	make -C tools

image: bootloader application tools
	[ -d image ] || mkdir image
	@echo "convert application image to upgrade image!!!"
	[ ! -f build_boot/lynxi_mcu_bootloader.bin ] || cp build_boot/lynxi_mcu_bootloader.bin image/
	$(CVIMG) build_app/lynxi_mcu.bin image/lynxi_mcu_upgrade.bin 3 
	$(MGBIN) build_boot/lynxi_mcu_bootloader.bin 0x2000 image/lynxi_mcu_upgrade.bin image/lynxi_mcu_merge.bin


.PHONY:clean
clean:
	make -C tools clean
	make -f common.mk BUILD_TARGET=applicaion clean
	make -f common.mk BUILD_TARGET=boot clean
	
